/* Copyright (c) [Year] [name of copyright holder]
 * [Software Name] is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *      http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package com.gitee.empty_null.core.pojo;

/**
 * @author xuhainan
 * @date 2023/8/23 16:35
 * @region hefei
 */
public record Empty<T>(int code, String msg, T data) {


    public static <T> Empty<T> success() {
        return success(null);
    }

    public static <T> Empty<T> success(T data) {
        return create(StatusCode.SUCCESS.getCode(), null, data);
    }

    public static <T> Empty<T> fail() {
        return fail("");
    }

    public static <T> Empty<T> fail(String msg) {
        return fail(StatusCode.FAIL.getCode(), msg);
    }

    public static <T> Empty<T> fail(int code, String msg) {
        return create(code, msg, null);
    }

    public static <T> Empty<T> create(StatusCode statusCode) {
        return create(statusCode, null);
    }

    public static <T> Empty<T> create(StatusCode statusCode, String msg) {
        return create(statusCode.getCode(), msg, null);
    }

    public static <T> Empty<T> create(StatusCode statusCode, T data) {
        return create(statusCode.getCode(), statusCode.getMsg(), data);
    }

    public static <T> Empty<T> create(int code, String msg, T data) {
        return new Empty<>(code, msg, data);
    }

}
